using UnityEngine;
using UnityEngine.UI;

public class StorylinePopup : MonoBehaviour
{
	public Text nameLabel;
	public Text characterText;
	public Image characterImg;
	public StorylineInfo storyline;

	private string characterName;

	public void Init(Player _character)
	{
		GetComponent<CanvasGroup>().alpha = 0f;
		characterName = _character.GetInfo().itemName;
		Invoke("InitPopup", 2f);
		
		GameCamera.Instance.SetZoom(_character.transform);
	}

	private void InitPopup()
	{
		GetComponent<CanvasGroup>().alpha = 1f;

		foreach (StorylineInfo.CharacterLines line in storyline.characterLines)
		{
			if (characterName == line.character)
			{
				nameLabel.text = line.character;
				characterText.text = "";
				for (int i = 0 ; i < line.lines.Count; i++)
				{
					characterText.text += (i != 0 ? "\n\n" : "" ) + line.lines[i];
				}
				
				InteractiveInfo interInfo = InteractiveManager.Instance.GetInfo(line.character);
				characterImg.sprite = interInfo.image;
				
				break;
			}
		}
	}

	public void OnClick_Close()
	{
		ScreensManager.Instance.RemovePopup(gameObject);
		GameCamera.Instance.RemoveZoom();
	}
}
